package br.com.leilao.dao;

import java.util.ArrayList;

import org.hibernate.Session;

import br.com.leilao.config.HibernateUtil;
import br.com.leilao.model.Perfil;

public class PerfilDAO extends GenericDAO<Perfil> {

	private Session sessao;

	@SuppressWarnings("unchecked")
	public Perfil findByAttr(Class<?> classe, String attr, String value) {
		try {
			sessao = HibernateUtil.getSessionFactory().openSession();
			sessao.beginTransaction();

			String sql = "from " + classe.getSimpleName() + " where " + attr
					+ " like '%" + value + "%'";

			Perfil list = (Perfil) sessao.createQuery(sql).uniqueResult();
			sessao.getTransaction().commit();
			return list;
		} catch (Exception e) {
			sessao.getTransaction().rollback();
			e.printStackTrace();
			return null;
		} finally {
			sessao.close();
		}
	}
}
